<?php
namespace Home\Controller;
use Think\Controller;
use Think;
/**
 * 返回消息类
 * 
 */
class TransmitController extends Controller {
	

	//返回文本类
	public function transmitText($openid, $content){
		$toUserName = "wilson";
		$textTpl="<xml>
					<ToUserName><![CDATA[%s]]></ToUserName>
					<FromUserName><![CDATA[%s]]></FromUserName>
					<CreateTime>%s</CreateTime>
					<MsgType><![CDATA[text]]></MsgType>
					<Content><![CDATA[%s]]></Content>
					</xml>";
		$result = sprintf($textTpl, $openid, $toUserName, time(), $content);
		//记录微信return_xml日志
		//$log_content = var_export($content, true)."|openid:".$openid."\n";
		//Think\Log::write($log_content,'','',C('LOG_PATH_MSXW_return_xml'));
		echo $result;
	 }
	
	function transmitPicText($openid, $arr_item){
		$toUserName = "wilson";
		$itemTpl = "<item>
						<Title><![CDATA[%s]]></Title> 
						<Description><![CDATA[%s]]></Description>
						<PicUrl><![CDATA[%s]]></PicUrl>
						<Url><![CDATA[%s]]></Url>
					  </item>
					";

		$item_str="";
		foreach ($arr_item as $item) {
			$item_str.=sprintf($itemTpl,$item['Title'],$item['Description'],$item['PicUrl'],$item['Url']);
		}

		$newsTp1="<xml>
						<ToUserName><![CDATA[%s]]></ToUserName>
						<FromUserName><![CDATA[%s]]></FromUserName>
						<CreateTime>%s</CreateTime>
						<MsgType><![CDATA[news]]></MsgType>
						<Content><![CDATA[]]></Content>
						<ArticleCount>%s</ArticleCount>
						<Articles>$item_str</Articles>
				 </xml>";
		$resultStr = sprintf($newsTp1, $openid, $toUserName, time(),  count($arr_item));
		//记录微信return_xml日志
		//$log_content = var_export($item_str, true)."|openid:".$openid."\n";
		//Think\Log::write($log_content,'','',C('LOG_PATH_MSXW_return_xml'));
		echo $resultStr;
	}

}


